#include <stdio.h>
#include <string.h>
#include <error.h>
#include <time.h>
#include <unistd.h>
#include "logger.h"

int get_time(char *gettime)
{
    if (NULL == gettime)
    {
        log_error("invalid input argument");
        return -1;
    }

    time_t rawtime = 0;
    struct tm ptm;

    time(&rawtime);

    if (localtime_r(&rawtime, &ptm) == NULL)
    {
        log_error("localtime_r failed");
        return -1;
    }

    if (strftime(gettime, 32, "%Y-%m-%d %H:%M:%S", &ptm) == 0)
    {
        log_error("strftime failed");
        return -1;
    }

    log_debug("get_time successfully: %s", gettime);

    return 0;
}

